package com.itheima.tlias.controller;

import com.itheima.tlias.annotation.LogOperation;
import com.itheima.tlias.pojo.*;
import com.itheima.tlias.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO
 *
 * @Author mr.luo
 * @Date 05 4月 2025 19:26
 */
@Slf4j
@RestController
@RequestMapping("/clazzs")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;

    /**
     * 班级列表查询
     */
    @GetMapping
    public Result findAll(ClazzsDTO clazzsDTO) {
        log.info("查询所有班级信息");
        PageResult<ClazzVO> pageResult = clazzService.findAll(clazzsDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据id删除班级
     */
    @LogOperation
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        log.info("根据id删除班级信息:{}", id);
        clazzService.delete(id);
        return Result.success();

    }

    /**
     * 新增班级
     */
    @LogOperation
    @PostMapping
    public Result add(@RequestBody AddClazzsDTO addClazzsDTO) {
        log.info("新增班级信息:{}", addClazzsDTO);
        clazzService.add(addClazzsDTO);
        return Result.success();
    }

    /**
     * 根据id查询班级
     */
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id) {
        log.info("根据id查询班级信息:{}", id);
        ClazzVO clazzVO = clazzService.findById(id);
        log.info("查询到的班级信息:{}", clazzVO);
        return Result.success(clazzVO);
    }

    /**
     * 修改班级
     */
    @LogOperation
    @PutMapping
    public Result update(@RequestBody ClazzVO clazzVO) {
        log.info("修改班级信息:{}", clazzVO);
        clazzService.update(clazzVO);
        return Result.success();
    }
    /**
     * 查询所有班级
     */
    @GetMapping("/list")
    public Result findAll() {
        log.info("查询所有班级信息");
      List<ClazzVO> clazzVOS = clazzService.findAllClass();
        return Result.success(clazzVOS);
    }
}
